package com.henghai.zhenxuan.ui.page.mine;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.henghai.zhenxuan.BR;
import com.henghai.zhenxuan.R;
import com.henghai.zhenxuan.data.config.AppConfig;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.kunminx.architecture.ui.page.BaseFragment;
import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.page.StateHolder;
import com.kunminx.architecture.ui.state.State;

public class InvitationCodeFragment extends BaseFragment {

    private InvitationCodeStates mStates;
    private static final String TAG = "InvitationCodeFragment";
    @Override
    protected void initViewModel() {
        mStates = getFragmentScopeViewModel(InvitationCodeStates.class);
//        Log.d("song", "initViewModel: "+mStates.codeImage.get());
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.fragment_invitation_code, BR.vm, mStates)
                .addBindingParam(BR.listener, new ListenerHandler())
                .addBindingParam(BR.clickProxy, new ClickProxy());
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: "+mStates.codeImage.get());
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public class ListenerHandler implements OnTitleBarListener {
        @Override
        public void onLeftClick(TitleBar titleBar) {
            OnTitleBarListener.super.onLeftClick(titleBar);
            nav().navigateUp();
        }

        @Override
        public void onRightClick(TitleBar titleBar) {
            OnTitleBarListener.super.onRightClick(titleBar);
        }
    }
    public class ClickProxy{
        public void back() {
            nav().popBackStack();
        }
    }
    public static class InvitationCodeStates extends StateHolder {
        public final State<String> codeImage = new State<>(AppConfig.INSTANCE.getMConfigs().user().get().getQrCode());

    }
}
